//
//  XQAttentionPopView.m
//  JoinPeso
//
//  Created by 小琦 on 2024/11/22.
//

#import "XQAttentionPopView.h"
#import "XQCustomEngeLabel.h"

@interface XQAttentionPopView()
@property (nonatomic,strong) UIView *centerView;
@property (nonatomic,strong) UIImageView *imageView;
@property (nonatomic,strong) UILabel *titleLb;
@property (nonatomic,strong) UIButton *closeButton;
@property (nonatomic,strong) XQCustomEngeLabel *contentLb;
@property (nonatomic,strong) UIButton *confimButton;
@end

@implementation XQAttentionPopView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self makeUI];
        [self makeConstraints];
    }
    return self;
}

- (void)makeUI {
    [self addSubview:self.centerView];
    [self.centerView addSubview:self.imageView];
    [self.imageView addSubview:self.titleLb];
    [self.imageView addSubview:self.closeButton];
    [self.imageView addSubview:self.contentLb];
    [self.centerView addSubview:self.confimButton];
}

- (void)makeConstraints {
    [self.centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
        (void)make.center;
    }];
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@0);
        make.left.equalTo(@12);
        make.right.equalTo(@-12);
        make.height.mas_equalTo(169);
    }];
    [self.confimButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageView.mas_bottom).offset(10);
        make.left.equalTo(@12);
        make.right.equalTo(@-12);
        make.width.mas_equalTo([UIScreen mainScreen].width - 24);
        make.height.mas_equalTo(45);
        make.bottom.equalTo(@0);
    }];
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        (void)make.centerX;
        make.top.equalTo(@12);
    }];
    [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@12);
        make.right.equalTo(@-10);
        make.height.width.mas_equalTo(22);
    }];
    [self.contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@20);
        make.right.equalTo(@-20);
        make.top.equalTo(@73);
        make.height.mas_equalTo(50);
    }];
}

#pragma mark - setter

- (void)setTitle:(NSString *)title {
    self.titleLb.text = title;
}

- (void)setContent:(NSString *)content {
    self.contentLb.text = content;
}

#pragma mark - private

- (void)confimClick {
    if (self.confimHandle) {
        self.confimHandle();
    }
}

- (void)closeClick {
    if (self.closeHandle) {
        self.closeHandle();
    }
}

#pragma mark - lazy

- (UIView *)centerView {
    if (!_centerView) {
        _centerView = [[UIView alloc] init];
    }
    return _centerView;
}

- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
        _imageView.image = [UIImage imageNamed:@"pod_exit"];
        [_imageView setUserInteractionEnabled:YES];
    }
    return _imageView;
}

- (UIButton *)confimButton {
    if (!_confimButton) {
        _confimButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_confimButton setTitle:@"Confirm" forState:UIControlStateNormal];
        [_confimButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _confimButton.titleLabel.font = [UIFont boldSystemFontOfSize:20];
        _confimButton.backgroundColor = [UIColor blueColor];
        _confimButton.layer.cornerRadius = 22.5;
        [_confimButton addTarget:self action:@selector(confimClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _confimButton;
}

- (UILabel *)titleLb {
    if (!_titleLb) {
        _titleLb = [[UILabel alloc] init];
        _titleLb.textColor = [UIColor whiteColor];
        _titleLb.font = [UIFont boldSystemFontOfSize:18];
    }
    return _titleLb;
}

- (UIButton *)closeButton {
    if (!_closeButton) {
        _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeButton setImage:[UIImage imageNamed:@"pop_close"] forState:UIControlStateNormal];
        [_closeButton addTarget:self action:@selector(closeClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _closeButton;
}

- (XQCustomEngeLabel *)contentLb {
    if (!_contentLb) {
        _contentLb = [[XQCustomEngeLabel alloc] init];
        _contentLb.edgtInsets = UIEdgeInsetsMake(5, 10, 5, 10);
        _contentLb.numberOfLines = 0;
        _contentLb.textAlignment = NSTextAlignmentCenter;
        _contentLb.textColor = kOrangeColor;
        _contentLb.backgroundColor = [kOrangeColor colorWithAlphaComponent:0.2];
        _contentLb.font = [UIFont boldSystemFontOfSize:14];
        _contentLb.layer.cornerRadius = 15;
    }
    return _contentLb;
}

@end
